﻿using DevExpress.Mvvm.POCO;
using DevExpress.XtraEditors;
using DXApplication_TestDemo.Models.ProgramModel;
using DXApplication_TestDemo.ViewModels;

namespace DXApplication_TestDemo.Views
{
    public partial class MeasView : XtraForm
    {
        public MeasView()
        {
            InitializeComponent();

            //使用单例vm保证数据一致性
            mvvmContext1.SetViewModel(typeof(MeasViewModel), ProgramModel.Instance.MeasViewModels);

            InitializeBindings();
        }

        // 初始化绑定
        void InitializeBindings()
        {
            var fluent = mvvmContext1.OfType<MeasViewModel>();
            fluent.SetBinding(textEdit1, textEdit1 => textEdit1.Text, vm => vm.MeasModels.Name);

            var viewModel = mvvmContext1.GetViewModel<MeasViewModel>();
            labelControl1.DataBindings.Add("Text", viewModel.MeasModels, "Name", true);
            //textEdit1.DataBindings.Add("Text", viewModel.MeasModels, "Name", true);

        }

    }
}
